package cn.kaiux.bigdata.homework.week02;

import lombok.*;
import org.apache.hadoop.io.WritableComparable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

/**
 * @author kaiux@foxmail.com
 * @date 2022/5/9 19:17
 */
@Getter
@Setter
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class PhoneTrafficDTO implements WritableComparable<PhoneTrafficDTO> {

    @Builder.Default
    private long up = 0L;

    @Builder.Default
    private long down = 0L;

    @Override
    public int compareTo(PhoneTrafficDTO o) {
        return (this.down + this.up) > (o.down + o.up) ? -1 : 1;
    }

    @Override
    public void write(DataOutput dataOutput) throws IOException {
        dataOutput.writeLong(up);
        dataOutput.writeLong(down);
    }

    @Override
    public void readFields(DataInput dataInput) throws IOException {
        up = dataInput.readLong();
        down = dataInput.readLong();
    }
}